'use strict';

async function ajax(options) {
    let {method, url, data, success} = options;
    return new Promise( res => {
        const xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                res(JSON.parse(xhttp.responseText))
            }
        }

        xhttp.open(method, url);
        xhttp.send(data);
    }).then(response => typeof success == 'function' ? success(response) : response);
}

async function get(url) {
    return await ajax({
        method: 'GET',
        url
    })
}